package com.example.demo;

import javax.annotation.Resource;

import com.alibaba.druid.pool.DruidDataSource;
import com.example.demo.aop.webLog;
import com.example.demo.bean.Person;
import com.example.demo.dao.db.DemoMapper;
import com.example.demo.dao.db2.Demo2Mapper;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lile on 2020-01-16.
 */
@RestController
@RequestMapping(value = "/AutoDealerVideo")
public class TestController {

    @Autowired
    UserService service;

    @Autowired
    DemoMapper demoMapper;

    @Autowired
    Person person;

    @Resource
    private RedisTemplate<String,Object> redisTemplate; //默认的

    @Resource
    RedisTemplate<String,Person> redisCustomerTemplate; //自定义序列化的 db下的redisconfig

    @RequestMapping("/getInfo")
    @webLog(value = "2",id = "'param id is ' + #age") //aop的使用
    public String getInfo(String name, Integer age){
        System.out.println(service.getUserCount(age));
        return name + ":" + age;
    }


    @RequestMapping("/getInfo1")
    public String getInfo1(String name, Integer age){
        return name + ":" + age;
    }

    @RequestMapping("/update")
    public String cacheUpdate(Integer total){
        service.updateCacheUserCount(total);
        return "success";
    }

    @RequestMapping("/get")
    public String getCache(Integer total){
        service.getUserCount(total);
        return "success";
    }

    @RequestMapping("/del")
    public String delCache(Integer total){
        service.delCacheUserCount(total);
        return "success";
    }

    @RequestMapping("/redis")
    public String redis(Integer total) {
        redisCustomerTemplate.opsForValue().set("name1", person);
        Person p = redisCustomerTemplate.opsForValue().get("name1");
        System.out.println(p);
        return "success";
    }
}
